package com.ruoyi.otc.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.otc.domain.OperationLog;
import com.ruoyi.otc.service.IOperationLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 操作日志Controller
 * 
 * @author gjp
 * @date 2024-05-22
 */
@Controller
@RequestMapping("/otc/log")
public class OperationLogController extends BaseController
{
    private String prefix = "otc/log";

    @Autowired
    private IOperationLogService operationLogService;

    @RequiresPermissions("otc:log:view")
    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询操作日志列表
     */
    @RequiresPermissions("otc:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OperationLog operationLog)
    {
        startPage();
        List<OperationLog> list = operationLogService.selectOperationLogList(operationLog);
        return getDataTable(list);
    }

    /**
     * 导出操作日志列表
     */
    @RequiresPermissions("otc:log:export")
    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OperationLog operationLog)
    {
        List<OperationLog> list = operationLogService.selectOperationLogList(operationLog);
        ExcelUtil<OperationLog> util = new ExcelUtil<OperationLog>(OperationLog.class);
        return util.exportExcel(list, "操作日志数据");
    }

    /**
     * 新增操作日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存操作日志
     */
    @RequiresPermissions("otc:log:add")
    @Log(title = "操作日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OperationLog operationLog)
    {
        return toAjax(operationLogService.insertOperationLog(operationLog));
    }

    /**
     * 修改操作日志
     */
    @RequiresPermissions("otc:log:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        OperationLog operationLog = operationLogService.selectOperationLogById(id);
        mmap.put("operationLog", operationLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存操作日志
     */
    @RequiresPermissions("otc:log:edit")
    @Log(title = "操作日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OperationLog operationLog)
    {
        return toAjax(operationLogService.updateOperationLog(operationLog));
    }

    /**
     * 删除操作日志
     */
    @RequiresPermissions("otc:log:remove")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(operationLogService.deleteOperationLogByIds(ids));
    }
}
